import {
  createRouter,
  createWebHashHistory,
  RouteRecordRaw
} from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    meta: {
      title: '首页'
    },
    component: () => import(/* webpackChunkName: "home" */ '../views/home.vue')
  },
  {
    path: '/notFound',
    name: 'NotFound',
    meta: {
      title: '未找到'
    },
    component: () => import('../views/notFound.vue')
  },
  {
    path: '/404',
    name: '404',
    meta: {
      title: '404'
    },
    component: () => import('../views/404.vue')
  },
  { path: "/:pathMatch(.*)", redirect: '/404' },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes,
})

router.beforeEach(async (to, from) => {
  console.log(to.meta , '---(to.meta ')
  const metaTitlt = (to.meta && to.meta.title) || ''
  document.title = `${metaTitlt} - EPFE`
  if (from.path !== '/') {}

})

export default router
